from django.db import models
from django.contrib.auth.models import User

class DocumentVersion(models.Model):
    """文档版本模型"""
    document = models.ForeignKey('Document', verbose_name='文档',
                                on_delete=models.CASCADE,
                                related_name='versions')
    content = models.TextField('内容')
    version = models.PositiveIntegerField('版本号')
    comment = models.CharField('版本说明', max_length=200, blank=True)
    created_by = models.ForeignKey(User, verbose_name='创建者',
                                  on_delete=models.CASCADE,
                                  related_name='document_versions')
    created_at = models.DateTimeField('创建时间', auto_now_add=True)

    class Meta:
        verbose_name = '文档版本'
        verbose_name_plural = verbose_name
        ordering = ['-version']
        unique_together = ['document', 'version']

    def __str__(self):
        return f'{self.document.title} - v{self.version}' 